﻿namespace Wuqi.Webdiyer
{
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    public class SPVarRegForm : Form
    {
        private Button btn_add;
        private Button btn_cancel;
        private Button btn_ok;
        private Button btn_rem;
        private ComboBox cmb_dtype;
        private IContainer components;
        private GroupBox groupBox1;
        private Label label1;
        private Label label2;
        private Label label3;
        private ListBox listBox1;
        private string sqlVariables;
        private TextBox tb_size;
        private TextBox tb_vname;

        public SPVarRegForm(string sqlvars)
        {
            this.InitializeComponent();
            this.sqlVariables = sqlvars;
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            if (this.tb_vname.Text.Trim().Length == 0)
            {
                MessageBox.Show("变量名称不能为空");
            }
            else
            {
                string str = this.tb_vname.Text.Trim().Trim(new char[] { '@' });
                string str2 = this.cmb_dtype.SelectedItem.ToString();
                string str3 = this.tb_size.Text.Trim();
                if (str3.Length > 0)
                {
                    str3 = "(" + str3 + ")";
                }
                this.listBox1.Items.Add("@" + str + "  " + str2 + str3);
            }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            StringBuilder builder = new StringBuilder();
            foreach (string str in this.listBox1.Items)
            {
                builder.Append(str).Append(",");
            }
            this.sqlVariables = builder.ToString().Trim(new char[] { ',' });
        }

        private void btn_rem_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.RemoveAt(this.listBox1.SelectedIndex);
        }

        private void cmb_dtype_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (this.cmb_dtype.SelectedItem.ToString().ToLower())
            {
                case "int":
                case "bit":
                case "tinyint":
                case "smallint":
                case "bitint":
                case "datetime":
                case "smalldatetime":
                    this.tb_size.Text = "";
                    this.tb_size.Enabled = false;
                    return;
            }
            this.tb_size.Enabled = true;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.label1 = new Label();
            this.label2 = new Label();
            this.label3 = new Label();
            this.btn_add = new Button();
            this.tb_vname = new TextBox();
            this.tb_size = new TextBox();
            this.cmb_dtype = new ComboBox();
            this.btn_rem = new Button();
            this.listBox1 = new ListBox();
            this.btn_ok = new Button();
            this.btn_cancel = new Button();
            this.groupBox1 = new GroupBox();
            this.groupBox1.SuspendLayout();
            base.SuspendLayout();
            this.label1.AutoSize = true;
            this.label1.Location = new Point(12, 0x1a);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x43, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "变量名称：";
            this.label2.AutoSize = true;
            this.label2.Location = new Point(12, 0x3b);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x43, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "数据类型：";
            this.label3.AutoSize = true;
            this.label3.Location = new Point(15, 0x5e);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x43, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "变量宽度：";
            this.btn_add.Location = new Point(0xd4, 0x27);
            this.btn_add.Name = "btn_add";
            this.btn_add.Size = new Size(0x24, 0x17);
            this.btn_add.TabIndex = 3;
            this.btn_add.Text = ">>";
            this.btn_add.UseVisualStyleBackColor = true;
            this.btn_add.Click += new EventHandler(this.btn_add_Click);
            this.tb_vname.Location = new Point(0x56, 0x1a);
            this.tb_vname.Name = "tb_vname";
            this.tb_vname.Size = new Size(0x72, 20);
            this.tb_vname.TabIndex = 4;
            this.tb_size.Location = new Point(0x56, 0x5e);
            this.tb_size.Name = "tb_size";
            this.tb_size.Size = new Size(0x72, 20);
            this.tb_size.TabIndex = 5;
            this.cmb_dtype.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmb_dtype.FormattingEnabled = true;
            this.cmb_dtype.Location = new Point(0x56, 0x3b);
            this.cmb_dtype.Name = "cmb_dtype";
            this.cmb_dtype.Size = new Size(0x72, 0x15);
            this.cmb_dtype.TabIndex = 6;
            this.cmb_dtype.SelectedIndexChanged += new EventHandler(this.cmb_dtype_SelectedIndexChanged);
            this.btn_rem.Location = new Point(0xd4, 0x54);
            this.btn_rem.Name = "btn_rem";
            this.btn_rem.Size = new Size(0x24, 0x17);
            this.btn_rem.TabIndex = 7;
            this.btn_rem.Text = "<<";
            this.btn_rem.UseVisualStyleBackColor = true;
            this.btn_rem.Click += new EventHandler(this.btn_rem_Click);
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Location = new Point(0x102, 0x1a);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new Size(0xb2, 0x5f);
            this.listBox1.TabIndex = 8;
            this.btn_ok.DialogResult = DialogResult.OK;
            this.btn_ok.Location = new Point(0x89, 0x9a);
            this.btn_ok.Name = "btn_ok";
            this.btn_ok.Size = new Size(0x4b, 0x17);
            this.btn_ok.TabIndex = 9;
            this.btn_ok.Text = "确定(&O)";
            this.btn_ok.UseVisualStyleBackColor = true;
            this.btn_ok.Click += new EventHandler(this.btn_ok_Click);
            this.btn_cancel.DialogResult = DialogResult.Cancel;
            this.btn_cancel.Location = new Point(0xe4, 0x9a);
            this.btn_cancel.Name = "btn_cancel";
            this.btn_cancel.Size = new Size(0x4b, 0x17);
            this.btn_cancel.TabIndex = 10;
            this.btn_cancel.Text = "取消(&C)";
            this.btn_cancel.UseVisualStyleBackColor = true;
            this.groupBox1.Controls.Add(this.tb_vname);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.listBox1);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.btn_rem);
            this.groupBox1.Controls.Add(this.btn_add);
            this.groupBox1.Controls.Add(this.cmb_dtype);
            this.groupBox1.Controls.Add(this.tb_size);
            this.groupBox1.Location = new Point(12, 12);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x1ba, 0x88);
            this.groupBox1.TabIndex = 11;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "注册变量";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1d3, 0xba);
            base.ControlBox = false;
            base.Controls.Add(this.groupBox1);
            base.Controls.Add(this.btn_cancel);
            base.Controls.Add(this.btn_ok);
            base.FormBorderStyle = FormBorderStyle.FixedDialog;
            base.Name = "SPVarRegForm";
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "注册存储过程变量";
            base.Load += new EventHandler(this.SPVarRegForm_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            base.ResumeLayout(false);
        }

        private void SPVarRegForm_Load(object sender, EventArgs e)
        {
            this.cmb_dtype.DataSource = Enum.GetNames(typeof(SqlDbType));
            this.cmb_dtype.SelectedItem = "Int";
            if (this.sqlVariables.Length > 0)
            {
                foreach (string str in this.sqlVariables.Split(new char[] { ',' }))
                {
                    this.listBox1.Items.Add(str);
                }
            }
        }

        public string SqlVariables
        {
            get
            {
                return this.sqlVariables;
            }
            set
            {
                this.sqlVariables = value;
            }
        }
    }
}

